@echo off
REM Windows环境下构建Go启动器脚本
REM 替代build_launchers.sh在Windows环境下的功能

echo Building launchers for Windows...

REM 检查Go是否已安装
where go >nul 2>&1
if %errorlevel% NEQ 0 (
    echo Error: Go is not installed or not in PATH
    echo Please install Go 1.21+ from https://golang.org/dl/
    exit /b 1
)

REM 创建bin目录（如果不存在）
if not exist "bin" mkdir "bin"

REM 构建Windows 64位启动器
echo Building Windows 64-bit launcher...
set GOOS=windows
set GOARCH=amd64
go build -o bin/launcher_windows.exe src/launcher/main.go
if %errorlevel% NEQ 0 (
    echo Error: Failed to build Windows 64-bit launcher
    exit /b 1
)

echo Windows 64-bit launcher built successfully: bin/launcher_windows.exe

REM 构建Linux 64位启动器 (x86)
echo Building Linux 64-bit launcher (x86)...
set GOOS=linux
set GOARCH=amd64
go build -o bin/launcher_linux_x86 src/launcher/main.go
if %errorlevel% NEQ 0 (
    echo Error: Failed to build Linux 64-bit launcher (x86)
    exit /b 1
)

echo Linux 64-bit launcher (x86) built successfully: bin/launcher_linux_x86

REM 构建Linux ARM启动器
echo Building Linux ARM launcher...
set GOOS=linux
set GOARCH=arm
go build -o bin/launcher_linux_arm src/launcher/main.go
if %errorlevel% NEQ 0 (
    echo Error: Failed to build Linux ARM launcher
    exit /b 1
)

echo Linux ARM launcher built successfully: bin/launcher_linux_arm

REM 构建Linux ARM64启动器
echo Building Linux ARM64 launcher...
set GOOS=linux
set GOARCH=arm64
go build -o bin/launcher_linux_arm64 src/launcher/main.go
if %errorlevel% NEQ 0 (
    echo Error: Failed to build Linux ARM64 launcher
    exit /b 1
)

echo Linux ARM64 launcher built successfully: bin/launcher_linux_arm64

echo.
echo All launchers built successfully!
echo.
echo To use PyInstallerEx, run:
echo   python -m PyInstallerEx test/test_script.py --cfg test/test_config.json

exit /b 0